#include<iostream>
#include<unistd.h>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
using namespace std;

//从键盘读取数据-写入管道-读取管道-写到屏幕
int main()
{
    int fds[2];
    char buffer[100];
    int len;
    if(pipe(fds)==-1)
    {
        perror("pipe");
        exit(1);
    }

    while(fgets(buffer,sizeof(buffer),stdin))
    {
        len=strlen(buffer);
        if(len!= write(fds[1],buffer,len))
        {
            perror("write");
            exit(1);
        }
    memset(buffer,0x00,sizeof(buffer));
    //read pipe
    if((len=read(fds[0],buffer,sizeof(buffer)))==-1)
    {
        perror("read");
        exit(1);
    }
    //write std
    if(write(1,buffer,sizeof(buffer))!=len)
    {
        perror("write 1");
        return 1;
    }
    }
    return 0;
}